package com.apexedu.eas.filter;


import com.apexedu.framework.util.ConfigUtil;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by ly on 2015/6/27.
 */
public class LoginFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        Object isLogin = ((HttpServletRequest)servletRequest).getSession().getAttribute("isLogin");
        if(isLogin == null){
            ((HttpServletResponse)servletResponse).sendRedirect(ConfigUtil.getString("loginPage"));// 返回登录页面
        }else{
            Object userid = ((HttpServletRequest)servletRequest).getSession().getAttribute("userid");
            ((HttpServletRequest)servletRequest).getSession().setAttribute("userid",userid);
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }

    public void destroy() {

    }
}
